// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue';
import VueResource from 'vue-resource';
// import App from './App'
// import router from './router'
import zcCalendarHeader from './zc-calendar-header';
import zcCalendarBody from './zc-calendar-body';
require('./tg_mobile_reset.css');
Vue.use(VueResource);
require('./rem.js');
Vue.config.productionTip = false;//来关闭生产模式下给出的提示

/* eslint-disable no-new */
new Vue({
  el: '#app',
  // router,
  // template: '<App/>',
  data:{
  	dateObj:{
  		monthCount:6,
  		// year:'2013',//起始年份
  		// month:'8',//起始月份
  	},
  	dateArr:[],
  	testArr:[1,2,3],
  },
  components: { //声明要使用的组件@zhch
  	zcCalendarHeader:zcCalendarHeader,
  	zcCalendarBody:zcCalendarBody
  },
  methods: {
  	monthWeeks(firstDay,lastDay) {//依据当月一号是周几与当月的天数计算当月会有几周
  		return 1+Math.ceil( (firstDay+lastDay-8)/7 );
  	},
  	turnArr() {//将传入的信息转换成数组
  		var count = this.dateObj.monthCount;
  		var tmpObj = {},weekArr = [],evyWeekArr = [],dayObj={};
  		var nowTime = new Date();//如未传起止年月，则以当前本地系统时间为准
  		var currYear = this.dateObj.year||nowTime.getFullYear(),
  			currMonth = this.dateObj.month||(nowTime.getMonth()+1),
  			currDay = new Date(currYear,currMonth,1).getTime(),
  			evyDay = -1,//每一天是几号
  			firstDate=1,
  			maxDay = 31,
  			currWeekCount=6;
  		for(var i=0;i<count;i++) {//循环出月数
  			tmpObj = {};
  			if(i===0) {
  				nowTime = new Date(currYear,currMonth-1,1);
  			}else {
  				nowTime = new Date(currYear,currMonth,1);//此处month作为索引
  			}         
  			currYear = nowTime.getFullYear();
  			currMonth = nowTime.getMonth()+1;//此处month为当前显示
  			firstDate = nowTime.getDay();
  			maxDay = new Date(currYear,currMonth,0).getDate();
  			currWeekCount = this.monthWeeks(firstDate,maxDay);
  			tmpObj.mTitle = currYear+'年'+currMonth+'月';//每一个月的标题
  			tmpObj.weekArr = [];
  			for(var j=0;j<currWeekCount;j++) { //周数
  				evyWeekArr = [];//一周七天
  				for(var k=1;k<=7;k++) { //依据第几周和当月的1号是周几来计算每一天是几号,k值的起始值决定了星期的起始值
  					evyDay = (7*j)+(k-firstDate);
  					
  					if(evyDay<1||evyDay>maxDay) {
  						dayObj = {
  							date:'',
  							timestamp:''
  						}

  					}else {
  						dayObj = {
  							date:evyDay,
  							timestamp:new Date(currYear,(currMonth-1),evyDay).getTime()
  						}
  					}
  					evyWeekArr.push(dayObj);
  					nowTime = new Date(dayObj.timestamp);//更新时间对象，只确保年月正确
  				}
  				tmpObj.weekArr.push(evyWeekArr);
  			}
  			this.dateArr.push(tmpObj);

  		}
  	}
  },
  created() {
  	this.turnArr();
  }
})
